package nag.arvind.gudiseva.singleton;

public class SingletonClass {

	private static SingletonClass singletonClass = new SingletonClass();
	
	/* A private Constructor prevents any other 
	 * class from instantiating.
	 */
	private SingletonClass(){
		// Exists only to defeat instantiation.
		if (singletonClass != null) {
            throw new IllegalStateException("Already instantiated");
        }
	}
	
	/* Static 'instance' method */
	public static SingletonClass getInstance(){
		if(singletonClass == null) {
			singletonClass = new SingletonClass();
	      }
	      return singletonClass;
	}
	
	/* Other methods protected by singleton-ness */
	protected static void demoMethod(){
		System.out.println("demoMethod for SingletonClass");
	}

	public static void demoMethodPublic(){
		System.out.println("demoMethod for SingletonClass");
	}

}
